package com.kk.base.entity.admin;

import javax.persistence.*;
import com.kk.base.entity.BaseEntity;
import com.kk.base.entity.common.Sex;
import com.kk.base.entity.home.BranchTypeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import com.kk.base.annotion.ValidateEntity;

/**
 * 后台用户实体类
 * @author Administrator
 *
 */
@EqualsAndHashCode(callSuper = true)
@ToString
@Data
@Entity
@Table(name="user")
@EntityListeners(AuditingEntityListener.class)
public class User extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	public static final int ADMIN_USER_STATUS_ENABLE = 1;//用户状态正常可用
	public static final int ADMIN_USER_STATUS_UNABLE = 0;//用户状态不可用
	
	@ManyToOne
	@JoinColumn(name="role_id")
	private Role role;//用户所属角色
	
	@ValidateEntity(required=true, requiredLength =true,minLength=2,maxLength=18,errorRequiredMsg="登录名称不能为空!",
			errorMinLengthMsg="登录名称长度需大于2!",errorMaxLengthMsg="登录名称长度不能大于18!")
	@Column(name="username",nullable=false,length=18,unique=true)
	private String username;//用户名
	
	@ValidateEntity(required=true, requiredLength =true,minLength=4,maxLength=32,errorRequiredMsg="密码不能为空！",errorMinLengthMsg="密码长度需大于4!",errorMaxLengthMsg="密码长度不能大于32!")
	@Column(name="password",nullable=false,length=32)
	private String password;//登录密码
	
	@ValidateEntity(required=false)
	@Column(name="status",length=1)
	private int status = ADMIN_USER_STATUS_ENABLE;//用户状态,默认可用
	
	@ValidateEntity(required=false)
	@Column(name="head_pic",length=128)
	private String headPic;//用户头像
	
	@ValidateEntity(required=false)
	@Column(name="sex",length=1)
	private int sex = Sex.UNKONW;//用户性别

	@ValidateEntity(required=true,errorRequiredMsg="手机号不能为空！")
	@Column(name="mobile",length=12)
	private String mobile;//用户手机号

	@ValidateEntity(required=false)
	@Column(name="address")
	private String address;//所在省市区

	@Column(name="office_address")
	private String officeAddress;//办公地址

	@Column(name="branch_type")
	private BranchTypeEnum branchType;  //网点类型

	@Enumerated
	@Column(name = "user_type")
	private UserRoleTypeEnum userType; //后台用户类型

	@Column(name="id_card")
	private String idCard; //身份证号

	@Column(name="longitude_and_latitude")
	private String longitudeAndIatitude;  // 百度地图经纬度

	@Column(name="branch_id")
	private Long branchId;  //快递员所属网点

	@Transient
	private Long countCourier;//带看次数

}
